package countingFileWords;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

public class ComparatorByValue implements Comparator<String>{
	HashMap<String, Integer> map;
	
	public ComparatorByValue(Map<String, Integer> map2) {
		this.map = (HashMap<String, Integer>) map2;
	}
	@Override
	public int compare(String arg1,String arg2) {
		if(!map.containsKey(arg1) || !map.containsKey(arg2)) {
			return 0;
		}
		if(map.get(arg1) > map.get(arg2)) {
			return -1;
		}
		else if(map.get(arg1) == map.get(arg2)) {
			return 0;
		}
		else {
			return 1;
		}
	}
	

	
	

}
